<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue中的样式绑定</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .activated{
            color: red;
        }
    </style>
</head>
<body>
    <!-- <div id="app">
        <div @click="handleDivClick"
            :class="[activated]"
        >
            Hello  world
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                activated: ""
            },
            methods: {
                handleDivClick: function() {
                    this.activated = this.activated === "activated" ?
                        "" : "activated";
                }
            }
        })
    </script> -->


    <div id="app">
        <div :style="[styleObj, {fontSize: '20px'}]" @click="handleDivClick">
            Hello World
        </div>
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                styleObj: {
                    color: "black"
                }
            },
            methods: {
                handleDivClick: function() {
                    this.styleObj.color = this.styleObj.color === "black" ? "red" : "black";
                }
            },
        })
    </script>
</body>
</html>